<html>
<head>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/js/iw.js"></script>
    <style>
        [class*='col-xs-'] {
            margin-bottom: 10px;
        }

        .hide {
            display: none;
        }

        .pr_no {
            padding-right: 0;
        }
    </style>

</head>
<body class="container-fuild" style="padding-top: 8px;">
<form class="form-horizontal" id="form">
    <div class="col-xs-6">
        <div class="form-group">
            <label for="title" class="col-sm-3 control-label">应用名称</label>
            <div class="col-sm-8">
                <input type="text" style="display:none;" id="taskId" name="taskId"
                       value="<#if task??>${task.taskId}</#if>"/>
                <input type="text" class="form-control" id="title" name="title" placeholder="填入应用名称"
                       value="<#if task??>${task.title}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-4 control-label pr_no">应用图标</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="icon" name="icon" placeholder="填入图标链接地址"
                       value="<#if task??>${task.icon}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="packagename" class="col-sm-3 control-label">应用包名</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="packagename" name="packagename" placeholder="填入应用包名"
                       value="<#if task??>${task.packagename}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">调起协议</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="label" name="label" placeholder="填入跳转，为0时表示不变"
                       value="<#if task??>${task.label}<#else>Null</#if>">
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">展示奖励</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="increase" name="increase"
                       placeholder="当价格等于0时不可选择“按比例”奖励模式" value="<#if task??>${task.increase}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">指定设备</label>
            <div class="col-sm-8">
                <select class="form-control" id="channel" name="channel">
                    <option value="" <#if task?? && task.channel == ''>selected</#if>>不限设备</option>
                    <option value="vivo" <#if task?? && task.channel == 'vivo'>selected</#if>>限vivo</option>
                    <option value="oppo" <#if task?? && task.channel == 'oppo'>selected</#if>>限oppo</option>
                    <option value="huawei" <#if task?? && task.channel == 'huawei'>selected</#if>>限huawei</option>
                    <option value="meizu" <#if task?? && task.channel == 'meizu'>selected</#if>>限meizu</option>
                    <option value="meizu" <#if task?? && task.channel == 'test'>selected</#if>>限测试版本</option>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">任务排序</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="sort" name="sort" placeholder="升序排序"
                       value="<#if task??>${task.sort}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">客户单价(单位:分)</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="amount" name="amount"
                       placeholder="当价格等于0时不可选择“按比例”奖励模式" value="<#if task??>${task.amount}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">奖励类型</label>
            <div class="col-sm-8">
                <select class="form-control" id="type" name="type">
                    <#list types as type>
                        <option value="${type}" <#if task?? && task.type == type>selected</#if>>${type.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">试玩时间(单位:分钟)</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="minutes" name="minutes"
                       placeholder="填入试玩时间，单位：分钟，为0时不限" value="<#if task??>${task.minutes}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">奖励模式</label>
            <div class="col-sm-8">
                <select class="form-control" id="reward" name="reward">
                    <#list rewards as reward>
                        <option value="${reward}"
                                <#if task?? && task.reward == reward>selected</#if>>${reward.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">计算奖励(单位:分)</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="worth" name="worth" placeholder="随机奖励格式n:m，其他填n，单位：分"
                       value="<#if task??>${task.worth}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">客户名称</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="customer" name="customer" placeholder="填入客户名称，不填表示自营"
                       value="<#if task??>${task.customer}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">下载地址</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="href" name="href" placeholder="用户下载地址"
                       value="<#if task??>${task.href}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-3 control-label">步骤描述</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="contents" name="contents" placeholder="步骤描述"
                       value="<#if task??>${task.contents}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">任务状态</label>
            <div class="col-sm-8">
                <select class="form-control" id="status" name="status">
                    <option value="On" <#if task?? && task.status == 'On'>selected</#if>>上架</option>
                    <option value="Off" <#if task?? && task.status == 'Off'>selected</#if>>下架</option>
                </select>
            </div>
        </div>
    </div>
</form>
<div class="col-xs-2" style="width: 100%; text-align: center">
    <button style="width: 85px;" class="btn btn-success" id="save_btn">保存</button>
</div>
<script>

    $(function () {
        $("#save_btn").click(function () {
            if (!$("#title").val()) {
                alert("请填入应用名称！");
                return false;
            }
            if (!$("#icon").val()) {
                alert("请填入应用图标！");
                return false;
            }
            if (!$("#packagename").val()) {
                alert("请填入应用包名！");
                return false;
            }

            if (!$("#minutes").val()) {
                alert("请填入试玩时间！");
                return false;
            }
            if (!$("#increase").val()) {
                $("#increase").val(0)
            }
            if ($("#reward").val() == 'Random') {
                if (!/:|：/.test($("#worth").val())) {
                    alert("格式为n：m或者n:m，请填入正确的格式！");
                    return false;
                }
            } else {
                if (!/^[1-9]\d*$/.test($("#worth").val())) {
                    alert("请填入计算奖励需正整数！");
                    return false;
                }
            }
            $.ajax({
                type: "post",
                url: "/rouse/save",
                data: $("#form").serialize(),
                success: function (res) {
                    alert(res);
                    window.parent.iw.closeDialog();
                }
            });
        });
    });
</script>
</body>
</html>
